#include <Fl/Fl.H>
#include "GlWindow.hpp"
#include "gl.hpp"
#include <GL/glu.h>
#include "Controller.hpp"

using namespace std;
using namespace math;
GlWindow::GlWindow(int aX, int aY, int aW, int aH)
: Fl_Gl_Window(aX, aY, aW, aH)
{
   mController = 0;
   mIsInitialized = false;
}

int GlWindow::handle(int event)
{
   int r(0);
   if (event == FL_MOVE)
   {
      if (Fl::focus() != this) Fl::focus(this);
      //if (! this->active()) this->activate();
   }
   if (mController != 0)
   {
      r = mController->handle(event);
   }

   if (!r)
   {
      r = Fl_Gl_Window::handle(event);
   }
   return r;
}

void GlWindow::resize(int aX, int aY, int aW, int aH)
{
   Fl_Gl_Window::resize(aX, aY, aW, aH);
   glViewport(0,0,aW,aH);
}

void GlWindow::draw()
{
   if (!mIsInitialized) return Fl_Gl_Window::draw();

   mController->Draw();
}
